USE [OctoNetApps]
GO

/****** Object:  StoredProcedure [classified].[ClassifiedCategories_Save]    Script Date: 05/25/2011 07:01:54 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [classified].[ClassifiedCategories_Save]
	@ResourceID bigint,
	@CategoryID bigint,
	@ParentCategoryID bigint,
	@CategoryName nvarchar(100),
	@AdNameExample nvarchar(512),
	@ImageUrl varchar(512),
	@RedirectUrl varchar(512),
	@Time smalldatetime,
	@ReadOnly bit
AS
BEGIN

BEGIN TRY
	
		BEGIN TRANSACTION TR
	SET NOCOUNT ON;
	
    UPDATE classified.ClassifiedCategories
    SET ParentCategoryID = @ParentCategoryID,
		CategoryName = @CategoryName,
		AdNameExample = @AdNameExample,
		ImageUrl = @ImageUrl,
		RedirectUrl = @RedirectUrl,
		[ReadOnly] = @ReadOnly,
		[Time] = @Time
	WHERE ResourceID = @ResourceID AND CategoryID = @CategoryID
	
	IF @@ROWCOUNT = 0
	BEGIN
		INSERT INTO classified.ClassifiedCategories
		VALUES (@CategoryID, @ResourceID, @ParentCategoryID, @CategoryName, @AdNameExample, @ImageUrl, @RedirectUrl, @Time, @ReadOnly)
	END
	
	UPDATE classified.ClassifiedResources
		SET CategoryTreeVersion = CategoryTreeVersion+1 WHERE ResourceID = @ResourceID
	
		COMMIT TRANSACTION TR
    END TRY
    BEGIN CATCH
		ROLLBACK TRANSACTION TR
    END CATCH
	
END



GO


